package day14.demo2;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @Auther:小陈的Java
 */
public class ThreadNew {
    public static void main(String[] args) {
        Callable callable = new Num();
        FutureTask task = new FutureTask(callable);
        new Thread(task).start();
        try {
            Object result = task.get();
            System.out.println("结果为:"+result);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}
class Num implements Callable{
    int result =0;
    @Override
    public Object call() throws Exception {
        for (int i = 1; i <=100; i++) {
           result+=i;
        }

        return result;
    }
}
